package utils

import (
	"gopkg.in/ini.v1"
	"log"
)

var (
	// DbHost mysql
	DbHost string
	DbUser string
	DbPort string
	DbPwd  string
	DbName string

	// RedisHost redis
	RedisHost string
	RedisPort string
	RedisPwd  string

	// AppMode gin
	AppMode  string
	HttpPort string
	JwtKey   string

	Zone       int
	AccessKey  string
	SecretKey  string
	Bucket     string
	QiniuSever string
)

func init() {

	file, err := ini.Load("./config/config.ini")
	if err != nil {
		log.Println("配置文件加载错误请检查文件路径err:", err)
	}
	//if err != nil {
	//
	//}
	loadDb(file)
	loadRedis(file)
	LoadServer(file)
	LoadQiniu(file)
}

// mysql相关
func loadDb(file *ini.File) {
	DbHost = file.Section("mysql").Key("DbHost").MustString("localhost")
	DbUser = file.Section("mysql").Key("DbUser").MustString("root")
	DbPort = file.Section("mysql").Key("DbPort").MustString("3306")
	DbPwd = file.Section("mysql").Key("DbPwd").MustString("root")
	DbName = file.Section("mysql").Key("DbName").MustString("gin_blog")
}

// redis  相关
func loadRedis(file *ini.File) {
	RedisHost = file.Section("redis").Key("Host").MustString("localhost")
	RedisPort = file.Section("redis").Key("Port").MustString("6379")
	RedisPwd = file.Section("redis").Key("Pwd").MustString("admin")
}

//gin  相关

func LoadServer(file *ini.File) {
	AppMode = file.Section("server").Key("AppMode").MustString("debug")
	HttpPort = file.Section("server").Key("HttpPort").MustString(":3000")
	JwtKey = file.Section("server").Key("JwtKey").MustString("89js82js72")
}
func LoadQiniu(file *ini.File) {
	Zone = file.Section("qiniu").Key("Zone").MustInt(1)
	AccessKey = file.Section("qiniu").Key("AccessKey").String()
	SecretKey = file.Section("qiniu").Key("SecretKey").String()
	Bucket = file.Section("qiniu").Key("Bucket").String()
	QiniuSever = file.Section("qiniu").Key("QiniuSever").String()
}
